package com.css.fxfzaqbz.modules.data.controller;


import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.data.entity.DisposeManager;
import com.css.fxfzaqbz.modules.data.queryParams.DisposeManagerQueryParams;
import com.css.fxfzaqbz.modules.data.queryParams.DisposeVo;
import com.css.fxfzaqbz.modules.data.service.DisposeManagerService;
import com.css.fxfzaqbz.util.CreateGson;
import com.css.fxfzaqbz.util.PlatformPageUtils;
import com.css.fxfzaqbz.zcpt.sys.entity.SUser;
import com.css.fxfzaqbz.zcpt.sys.service.SUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/*
 * 处置要点分析
 * */
@RestController
@RequestMapping("/fxfzaqbz/data")
@Slf4j
public class DisposeManagerController {

    @Resource
    DisposeManagerService disposeManagerService;

    @PostMapping("/saveDisposeManager")
    public RestResponse saveDisposeManager(@RequestBody DisposeManager disposeManager) {
        RestResponse restResponse = null;
        try {
            disposeManagerService.saveDisposeManager(disposeManager);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("新增处置管理失败", e);
            restResponse = RestResponse.fail("新增处置管理失败!");
        }
        return restResponse;
    }


    /**
     * 根据 主键 id 查找处置分析数据
     *
     * @param id 主键 id
     * @return 查找数据
     */
    @GetMapping("/getDisposeManager/{id}")
    public RestResponse<DisposeManager> getDisposeManager(@PathVariable("id") String id) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(disposeManagerService.getDisposeManager(id));
        } catch (Exception e) {
            log.error("获取处置管理失败!", e);
            restResponse = RestResponse.fail("获取处置管理失败!");
        }
        return restResponse;
    }


    /**
     * 根据 id 批量删除处置要点信息
     *
     * @param ids 主键 id list
     * @return
     */
    @PostMapping("/delDisposeManager/{ids}")
    public RestResponse delDisposeManager(@PathVariable("ids") List<String> ids) {
        RestResponse restResponse = null;
        try {
            System.out.println(ids);
            disposeManagerService.delDisposeManager(ids);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("删除处置要点数据失败!", e);
            restResponse = RestResponse.fail("删除处置要点数据失败!");
        }
        return restResponse;
    }

    /**
     * 处置要点分析修改
     * @param disposeManager
     * @return
     */
    @PostMapping("/updateDisposeFX")
    public RestResponse<DisposeManager> updateDisposeFX(@RequestBody DisposeManager disposeManager) {
        RestResponse restResponse = null;
        try {
            disposeManagerService.updateDisposeFX(disposeManager);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("修改处置要点数据失败!", e);
            restResponse = RestResponse.fail("修改处置要点数据失败!");
        }
        return restResponse;
    }


    /**
     * 根据标签名称进行模糊查询
     */
    @GetMapping("/getAllDisposeManager")
    public RestResponse getAllDisposeManager(HttpServletRequest request, DisposeManagerQueryParams queryParams) {
        RestResponse restResponse = null;
        try {
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            queryParams.setCurPage(curPage);
            queryParams.setPageSize(pageSize);
            restResponse = RestResponse.succeed(disposeManagerService.getAllDisposeManager(queryParams));
        } catch (Exception e) {
            log.error("查询处置要点数据失败!", e);
            restResponse = RestResponse.fail("查询处置要点数据失败");
        }
        return restResponse;
    }

    /**
     * 处置要点管理修改
     * @param disposeManager
     * @return
     */
    @PostMapping("/updateDisposeManager")
    public RestResponse<DisposeManager> updateDisposeManager(@RequestBody DisposeManager disposeManager) {
        RestResponse restResponse = null;
        try {
            disposeManagerService.updateDisposeManager(disposeManager);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("修改处置要点数据失败!", e);
            restResponse = RestResponse.fail("修改处置要点数据失败!");
        }
        return restResponse;
    }

    /**
     * 根据 活动id 查找处置分析数据
     * @param id 主键 id
     * @return 查找数据
     */
    @GetMapping("/getDisposeManagerByIaId")
    public RestResponse getDisposeManagerByIaId(HttpServletRequest request,@RequestParam("id") String id) {
        RestResponse restResponse = null;
        try {
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            restResponse = RestResponse.succeed(disposeManagerService.getDisposeManagerByIaId(id,curPage,pageSize));
        } catch (Exception e) {
            log.error("获取处置管理失败!", e);
            restResponse = RestResponse.fail("获取处置管理失败!");
        }
        return restResponse;
    }

    //批量新增
    @PostMapping("/saveDisposeList")
    public RestResponse saveList(@RequestBody DisposeVo disposeVo) {
        RestResponse restResponse = null;
        try {
            disposeManagerService.saveList(disposeVo);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("新增处置管理失败", e);
            restResponse = RestResponse.fail("新增处置管理失败!");
        }
        return restResponse;
    }


    /**
     * 处置要点分析提交按钮接口
     *
     */
    @PostMapping("/updateSubmitButton/{ids}")
    public RestResponse updateSubmitButton(@PathVariable("ids") List<String> ids)  {
        RestResponse restResponse = null;
        try{
            disposeManagerService.updateSubmitButton(ids);
            restResponse = RestResponse.succeed("提交成功");
        }catch (Exception e){
            log.error("提交失败!",e);
            restResponse = RestResponse.fail("提交失败!");
        }
        return restResponse;
    }

}
